package com.zf.lease.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zf.common.annotation.Log;
import com.zf.common.core.controller.BaseController;
import com.zf.common.core.domain.AjaxResult;
import com.zf.common.enums.BusinessType;
import com.zf.lease.domain.RoomContract;
import com.zf.lease.service.IRoomContractService;
import com.zf.common.utils.poi.ExcelUtil;
import com.zf.common.core.page.TableDataInfo;

/**
 * 房间和契约关系Controller
 * 
 * @author ruoyi
 * @date 2024-10-07
 */
@RestController
@RequestMapping("/lease/RoomContract")
public class RoomContractController extends BaseController
{
    @Autowired
    private IRoomContractService roomContractService;

    /**
     * 查询房间和契约关系列表
     */
    @PreAuthorize("@ss.hasPermi('lease:RoomContract:list')")
    @GetMapping("/list")
    public TableDataInfo list(RoomContract roomContract)
    {
        startPage();
        List<RoomContract> list = roomContractService.selectRoomContractList(roomContract);
        return getDataTable(list);
    }

    /**
     * 导出房间和契约关系列表
     */
    @PreAuthorize("@ss.hasPermi('lease:RoomContract:export')")
    @Log(title = "房间和契约关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoomContract roomContract)
    {
        List<RoomContract> list = roomContractService.selectRoomContractList(roomContract);
        ExcelUtil<RoomContract> util = new ExcelUtil<RoomContract>(RoomContract.class);
        util.exportExcel(response, list, "房间和契约关系数据");
    }

    /**
     * 获取房间和契约关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('lease:RoomContract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(roomContractService.selectRoomContractByContractId(contractId));
    }

    /**
     * 新增房间和契约关系
     */
    @PreAuthorize("@ss.hasPermi('lease:RoomContract:add')")
    @Log(title = "房间和契约关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoomContract roomContract)
    {
        return toAjax(roomContractService.insertRoomContract(roomContract));
    }

    /**
     * 修改房间和契约关系
     */
    @PreAuthorize("@ss.hasPermi('lease:RoomContract:edit')")
    @Log(title = "房间和契约关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoomContract roomContract)
    {
        return toAjax(roomContractService.updateRoomContract(roomContract));
    }

    /**
     * 删除房间和契约关系
     */
    @PreAuthorize("@ss.hasPermi('lease:RoomContract:remove')")
    @Log(title = "房间和契约关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(roomContractService.deleteRoomContractByContractIds(contractIds));
    }
}
